<?php
namespace app\common\services;

use yii\helpers\Url;

/**
 * Class UrlService 控制全局 url 跳转信息
 * Author: yanhaoqiang
 * @package app\common\services
 */
class UrlService {

    /**
     * [buildMUrl 移动端url设置]
     * @param $path
     * @param array $params
     * @return string
     */
    public static function buildMUrl($path, $params = []) {
        //基础配置
        $domain_config = \Yii::$app->params['domain'];
        $path = Url::toRoute(array_merge([$path], $params));
        return $domain_config['m'] . $path;
    }

    /**
     * [buildWebUrl web端url 设置]
     * @param $path
     * @param array $params
     * @return string
     */
    public static function buildWebUrl($path, $params = []) {
        $domain_config = \Yii::$app->params['domain'];
        $path = Url::toRoute(array_merge([$path], $params));
        return $domain_config['web'] . $path;
    }

    /**
     * [buildWwwUrl 全局设置]
     * @param $path
     * @param array $params
     * @return string
     */
    public static function buildWwwUrl($path, $params = []) {
        $domain_config = \Yii::$app->params['domain'];
        $path = Url::toRoute(array_merge([$path], $params));
        return $domain_config['www'] . $path;
    }

    /**
     * [buildNullUrl 空跳转]
     * @return string
     */
    public static function buildNullUrl() {
        return "javascript:void(0);";
    }

    /**
     * [buildPicUrl 图片对应的url]
     * @param $bucket
     * @param $file_key
     * @return string
     */
    public static function buildPicUrl($bucket, $file_key) {
        $domain_config = \Yii::$app->params['domain'];
        $upload_config = \Yii::$app->params['upload'];
        return $domain_config['www'] . $upload_config[$bucket] . "/" . $file_key;
    }
}